home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / msdos / card / source / card.asm next >
Encoding:
Assembly Source File  |  1991-10-19  |  5.5 KB  |  360 lines

  1. ;********************************************************************
  2. ;
  3. ;    IC Memory Card Device Driver
  4. ;
  5. ;    1991.03.08    make By Ken
  6. ;
  7. ;********************************************************************
  8.         .386p
  9.  
  10. rmcode        segment dword public use16 'CODE'
  11. rmcode        ends
  12. pmcode        segment dword public use32 'CODE'
  13. pmcode        ends
  14. incode        segment dword public use16 'CODE'
  15. incode        ends
  16. DGROUP        group    rmcode,pmcode,incode
  17.  
  18. CARD_IO        equ    048Ah
  19. CARD_TOP    equ    0C0000000h
  20.  
  21. extrn        end_of_adr:byte
  22. extrn        hmemcpy:near
  23. extrn        gdt_init:near
  24. extrn        open_msg:near
  25.  
  26. rmcode        segment
  27.  
  28. device_head    label    word
  29.         dd    -1
  30.         dw    2000h
  31.         dw    strategy
  32.         dw    cmdentry
  33.         db    1
  34.  
  35. command        dw    init
  36.         dw    md_chk
  37.         dw    build_bpb
  38.         dw    exit
  39.         dw    read
  40.         dw    exit
  41.         dw    exit
  42.         dw    exit
  43.         dw    write
  44.         dw    write
  45.         dw    exit
  46.         dw    exit
  47.         dw    exit
  48.  
  49. cmd_pkt        dd    ?
  50.  
  51. BPB_tbl        label    word
  52. BPB_sect    dw    512        ; Sector Size
  53.         db    2        ; Alloc sect
  54.         dw    1        ; Sect offset
  55.         db    2        ; FAT Count
  56.         dw    64        ; Dir Entry
  57.         dw    256        ; Total Sector
  58. BPB_id        db    0        ; ID dummy
  59.         dw    1        ; FAT sect Count
  60.  
  61. BPB_ptr        dw    BPB_tbl
  62.  
  63. IPL_head    db    0,0,0,0,0,0
  64. CARD_offset    dd    0
  65.  
  66.         assume    cs:rmcode,ds:nothing
  67.  
  68. strategy    proc    far
  69.         mov    word ptr cs:[cmd_pkt],bx
  70.         mov    word ptr cs:[cmd_pkt+2],es
  71.         ret
  72. strategy    endp
  73.  
  74. req_head    struc
  75. req_len        db    ?
  76. req_unit    db    ?
  77. req_cmd        db    ?
  78. req_stat    dw    ?
  79. req_res        db    ?,?,?,?,?,?,?,?
  80. req_head    ends
  81.  
  82. cmdentry    proc    far
  83.         pushfd
  84.         pushad
  85.         push    ds
  86.         push    es
  87.         push    gs
  88.         push    fs
  89.  
  90.         les    bx,cs:[cmd_pkt]
  91.         mov    al,es:[bx].req_cmd
  92.         cmp    al,12
  93.         ja    error
  94.         xor    ah,ah
  95.         shl    ax,1
  96.         mov    si,offset command
  97.         add    si,ax
  98.  
  99.         push    cs
  100.         pop    ds
  101.  
  102.         assume    ds:DGROUP
  103.  
  104.         call    word ptr ds:[si]
  105.         jmp    ret_ent
  106.  
  107. error:        mov    ax,8100h+3
  108. ret_ent:    lds    bx,cs:[cmd_pkt]
  109.         mov    ds:[bx].req_stat, ax
  110.  
  111.         pop    fs
  112.         pop    gs
  113.         pop    es
  114.         pop    ds
  115.         popad
  116.         popfd
  117.         ret
  118.  
  119. cmdentry    endp
  120.  
  121. exit        proc    near
  122.         mov    ax,0100h    ; Nothing Return
  123.         ret
  124. exit        endp
  125.  
  126. init_head    struc
  127. init_len    db    ?
  128. init_unit    db    ?
  129. init_cmd    db    ?
  130. init_stat    dw    ?
  131. init_res    db    ?,?,?,?,?,?,?,?
  132. init_unit_max    db    ?
  133. init_break_ofs    dw    ?
  134. init_break_seg    dw    ?
  135. init_bpb_ofs    dw    ?
  136. init_bpb_seg    dw    ?
  137. init_head    ends
  138.  
  139. init        proc    near
  140.  
  141.         mov    es:[bx].init_unit_max,1
  142.         mov    es:[bx].init_break_ofs,offset DGROUP:end_of_adr
  143.         mov    es:[bx].init_break_seg,cs
  144.         mov    es:[bx].init_bpb_ofs,offset BPB_ptr
  145.         mov    es:[bx].init_bpb_seg,cs
  146.  
  147.         call    gdt_init
  148.         call    open_msg
  149.  
  150.         mov    ax,0100h            ; No Error
  151.         ret
  152.  
  153. init        endp
  154.  
  155. chk_head    struc
  156. chk_len        db    ?
  157. chk_unit    db    ?
  158. chk_cmd        db    ?
  159. chk_stat    dw    ?
  160. chk_res        db    ?,?,?,?,?,?,?,?
  161. chk_id        db    ?
  162. chk_now        dw    ?
  163. chk_head    ends
  164.  
  165. md_chk        proc    near
  166.         mov    dx,CARD_IO
  167.         in    al,dx
  168.         test    al,6
  169.         jnz    dev_not_rdy
  170.  
  171.         test    al,80h
  172.         jnz    md_chk_chg
  173.  
  174.         mov    es:[bx].chk_now,1
  175.         jmp    md_chk_ret
  176. md_chk_chg:
  177.         mov    es:[bx].chk_now,0FFFFh
  178. md_chk_ret:
  179.         mov    ax,0100h            ; No Error
  180.         ret
  181.  
  182. dev_not_rdy:    mov    ax,8100h+2
  183.         ret
  184.  
  185. md_chk        endp
  186.  
  187. build_head    struc
  188. build_len    db    ?
  189. build_unit    db    ?
  190. build_cmd    db    ?
  191. build_stat    dw    ?
  192. build_res    db    ?,?,?,?,?,?,?,?
  193. build_id    db    ?
  194. build_work    dd    ?
  195. build_bpb_ofs    dw    ?
  196. build_bpb_seg    dw    ?
  197. build_head    ends
  198.  
  199. boot_sec_chk    proc    near
  200.  
  201.         xor    eax,eax
  202.         mov    ax,cs
  203.         shl    eax,4
  204.         add    eax,offset IPL_head
  205.         mov    edi,eax
  206.  
  207.         xor    esi,esi
  208. boot_sec_lop:
  209.         push    esi
  210.         push    edi
  211.         add    esi,CARD_TOP
  212.         mov    ecx,6
  213.         call    hmemcpy
  214.         pop    edi
  215.         pop    esi
  216.  
  217.         cmp    word ptr [IPL_head],5049h
  218.         jne    boot_chk_2
  219.         cmp    byte ptr [IPL_head+2],4Ch
  220.         je    boot_chk_ok
  221.  
  222. boot_chk_2:    cmp    word ptr [IPL_head+3],5049h
  223.         jne    boot_chk_3
  224.         cmp    byte ptr [IPL_head+5],4Ch
  225.         je    boot_chk_ok
  226.  
  227. boot_chk_3:    add    esi,0100h
  228.         cmp    esi,0500h
  229.         jne    boot_sec_lop
  230.         stc
  231.         ret
  232.  
  233. boot_chk_ok:    mov    [CARD_offset],esi
  234.         clc
  235.         ret
  236.  
  237. boot_sec_chk    endp
  238.  
  239. build_bpb    proc
  240.         mov    dx,CARD_IO
  241.         in    al,dx
  242.         test    al,6
  243.         jnz    dev_not_rdy
  244.  
  245.         call    boot_sec_chk
  246.         jnc    build_bpb_get
  247.         mov    ax,8100h+8
  248.         ret
  249.  
  250. build_bpb_get:    xor    eax,eax
  251.         mov    ax,cs
  252.         shl    eax,4
  253.         add    eax,offset BPB_tbl
  254.         mov    edi,eax
  255.         mov    esi,CARD_TOP+11
  256.         add    esi,[CARD_offset]
  257.         mov    ecx,13
  258.         call    hmemcpy
  259.  
  260.         mov    es:[bx].build_bpb_ofs,offset BPB_tbl
  261.         mov    es:[bx].build_bpb_seg,cs
  262.  
  263. ;        mov    al,[BPB_id]
  264. ;        mov    es:[bx].build_id,al
  265.  
  266.         mov    al,es:[bx].build_id
  267.         xor    al,0FFh
  268.         mov    [BPB_id],al
  269.         mov    es:[bx].build_id,al
  270.  
  271.         mov    ax,0100h            ; No Error
  272.         ret
  273. build_bpb    endp
  274.  
  275. rdwt_head    struc
  276. rdwt_len    db    ?
  277. rdwt_unit    db    ?
  278. rdwt_cmd    db    ?
  279. rdwt_stat    dw    ?
  280. rdwt_res    db    ?,?,?,?,?,?,?,?
  281. rdwt_id        db    ?
  282. rdwt_buff_ofs    dw    ?
  283. rdwt_buff_seg    dw    ?
  284. rdwt_count    dw    ?
  285. rdwt_sect    dw    ?
  286. rdwt_head    ends
  287.  
  288. read        proc    near
  289.         mov    dx,CARD_IO
  290.         in    al,dx
  291.         test    al,6
  292.         jnz    rd_wt_err
  293.  
  294.         movzx    eax,es:[bx].rdwt_buff_seg
  295.         shl    eax,4
  296.         movzx    edx,es:[bx].rdwt_buff_ofs
  297.         add    eax,edx
  298.         mov    edi,eax
  299.  
  300.         movzx    eax,es:[bx].rdwt_sect
  301.         movzx    edx,[BPB_sect]
  302.         imul    eax,edx
  303.         add    eax,CARD_TOP
  304.         add    eax,[CARD_offset]
  305.         mov    esi,eax
  306.  
  307.         movzx    eax,es:[bx].rdwt_count
  308.         imul    eax,edx
  309.         mov    ecx,eax
  310.  
  311.         call    hmemcpy
  312.  
  313.         mov    ax,0100h            ; No Error
  314.         ret
  315.  
  316. rd_wt_err:    mov    es:[bx].rdwt_count,0
  317.         mov    ax,8100h+2
  318.         ret
  319.  
  320. read        endp
  321.  
  322. write        proc    near
  323.         mov    dx,CARD_IO
  324.         in    al,dx
  325.         test    al,6
  326.         jnz    rd_wt_err
  327.         test    al,1
  328.         jnz    write_prot
  329.  
  330.         movzx    eax,es:[bx].rdwt_buff_seg
  331.         shl    eax,4
  332.         movzx    edx,es:[bx].rdwt_buff_ofs
  333.         add    eax,edx
  334.         mov    esi,eax
  335.  
  336.         movzx    eax,es:[bx].rdwt_sect
  337.         movzx    edx,[BPB_sect]
  338.         imul    eax,edx
  339.         add    eax,CARD_TOP
  340.         add    eax,[CARD_offset]
  341.         mov    edi,eax
  342.  
  343.         movzx    eax,es:[bx].rdwt_count
  344.         imul    eax,edx
  345.         mov    ecx,eax
  346.  
  347.         call    hmemcpy
  348.  
  349.         mov    ax,0100h            ; No Error
  350.         ret
  351.  
  352. write_prot:    mov    es:[bx].rdwt_count,0
  353.         mov    ax,8100h+0
  354.         ret
  355.  
  356. write        endp
  357.  
  358. rmcode        ends
  359.         end
  360.